package com.qiang.demo05.service;

import com.qiang.demo05.dao.IstudentDao;
import com.qiang.demo05.dao.StudentDaoImp;
import com.qiang.demo05.domain.Student;
import com.qiang.demo05.factory.Factory;

import java.util.ArrayList;

public class StudentServiceImp implements IstudentService {


    //StudentDaoImp itd = new StudentDaoImp();
    IstudentDao itd = Factory.getStudentDao();

    @Override
    public void addStudent(Student st) {

        //IstudentDao itd = new IstudentDao();

        itd.addStudent(st);
    }

    @Override
    public void deleteStudent(String id) {
        //IstudentDao itd = new IstudentDao();
        itd.deleteStudent(id);

    }

    @Override
    public void updateStudent(String id, Student newst) {
        // IstudentDao itd = new IstudentDao();
        itd.updateStudent(id, newst);
    }

    @Override
    public ArrayList<Student> findStudent() {
        //IstudentDao itd = new IstudentDao();
        ArrayList<Student> student = itd.findStudent();
        return student;
    }


    //判断学号是否存在

    public boolean Exit(String id) {
        //IstudentDao itd = new IstudentDao();
        ArrayList<Student> student = itd.findStudent();
        //遍历集合
        for (int i = 0; i < student.size(); i++) {
            if (student.get(i) != null && student.get(i).getId().equals(id)) {
                return true;
            }
        }
        return false;
    }

}
